<?php
namespace app\index\controller;
use think\Controller;

class Hunter extends Controller
{

    /**
     * 申请
     * @return [type] [description]
     */
    public function set()
    {
        $post = input('post.');
        if(empty($post['user_id'])){
            $this->ajaxReturn(null, '参数错误', 201);
        }

        $user = db('user')->find($post['user_id']);
        if(empty($user)){
            $this->ajaxReturn(null, '无此用户', 205);
        }

        if(empty($post['name'])){
            $this->ajaxReturn(null, '未填写猎人姓名', 203);
        }

        if(empty($post['mobile'])){
            $this->ajaxReturn(null, '未填写猎人电话', 203);
        }

        $data['user_id']    = $post['user_id'];
        $data['name']       = $post['name'];
        $data['mobile']     = $post['mobile'];
        $data['status']     = 1;
        $data['ctime'] 	    = time();
        $data['cdate'] 	    = date('Y-m-d H:i:s');
        $res  = db('bounty_hunter')->insertGetId($data);
        if($res){
            $this->ajaxReturn(null, '申请成功，等待审核', 200);
        }else{
            $this->ajaxReturn(null, '申请失败', 204);
        }
    }



    /**
    **个人中心
    **/
    public function index()
    {
        $userId = input('get.user_id');
        if(empty($userId)){
            $this->ajaxReturn(null, '参数错误', 201);
        }

        $hunter = db('bounty_hunter')->where('user_id', $userId)->find();
		if ($hunter) {
            $hunter['num'] = db('position_view')->where(['type'=>2, 'cid'=>$hunter['id']])->count();
            $this->ajaxReturn($hunter, 'ok', 200);
        }else{
            $this->ajaxReturn(null, '数据为空', 200);
        }
    }







}
